package com.gosophia.accountManagement.action;


import java.net.URLEncoder;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.userManagement.dto.PermissionDTO;
import com.gosophia.userManagement.dto.UserAccountDTO;
import com.gosophia.userManagement.ws.UserManagementWebService;

/**
 * 获取账号详细信息
 * @author mayue
 *
 */
@Controller("FindUserAccountDetailAction")
@Scope("prototype")
public class FindUserAccountDetailAction extends BaseSupportAction {

    private static final long serialVersionUID = 1L;

    @Autowired
    private UserManagementWebService userManagementWebService;
    
    private UserAccountDTO userAccountDTO;
    
    /**
     * 角色json字符串
     */
    private String roleJsonString;
    /**
     * 合并权限字符串
     */
    private String mergePermissionJsonString;
    
    
    @Override
    public String _execute() throws Exception {
        userAccountDTO = userManagementWebService.findUserAcountByUserAcountId(userAccountDTO.getUserAccountId());
        if(userAccountDTO!=null){
            super.getRequestResult().setRsltCode("0");
            List<PermissionDTO> list2 = userAccountDTO.getMergePermissionDTOs();
            if(list2!=null && list2.size()!=0){
                mergePermissionJsonString = JSONArray.fromObject(list2).toString().replace("\"", "\\\"");
            }
        }else{
            super.getRequestResult().setRsltCode("1");
            super.getRequestResult().setMessage(URLEncoder.encode("该记录已被删除","utf-8"));
        }
        return SUCCESS;
    }

    public UserAccountDTO getUserAccountDTO() {
        return userAccountDTO;
    }
    public void setUserAccountDTO(UserAccountDTO userAccountDTO) {
        this.userAccountDTO = userAccountDTO;
    }
    public String getRoleJsonString() {
        return roleJsonString;
    }
    public void setRoleJsonString(String roleJsonString) {
        this.roleJsonString = roleJsonString;
    }
    public String getMergePermissionJsonString() {
        return mergePermissionJsonString;
    }
    public void setMergePermissionJsonString(String mergePermissionJsonString) {
        this.mergePermissionJsonString = mergePermissionJsonString;
    }
    
    
}
